import { reqCategoryList, reqBannerList, reqFloorList } from '@/api'
// home模块的小仓库
// state：仓库存储数据的地方
const state = {
    categoryList: [],
    bannerList: [],
    floorList: []
    
}
// mutations:修改state的唯一手段
const mutations = {
    CategoryList(state, val) {
        state.categoryList = val
    },
    BannerList(state, val) {
        state.bannerList = val
    },
    FloorList(state, val) {
        state.floorList = val
    },
}
// actions：处理action，可以书写自己的业务逻辑，也可以处理异步
const actions = {
    // 通过API里面的接口函数调用，向服务器发请求，获取服务器的数据
    async categoryList({ commit }) {
        let result = await reqCategoryList()
        // console.log(result)
        if (result.code == 200) {
            commit('CategoryList', result.data)
        }
    },
    // 获取首页轮播图的数据
    async getBannerList({ commit }) {
        let result = await reqBannerList()
        if (result.code == 200) {
            commit('BannerList', result.data)
        }
    },
    async getFloorList({ commit }) {
        let result = await reqFloorList()
        if (result.code == 200) {
            commit('FloorList', result.data)
        }
    }
}
// getters:理解为计算属性，用于简化仓库数据，让组件获取仓库的数据更加方便
const getters = {}
export default ({
    state,
    mutations,
    actions,
    getters
})